package org.yi.web.index;

import java.util.Locale;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.yi.core.annotation.Action;
import org.yi.core.common.Constants;
import org.yi.core.render.YiCaptchaRender;
import org.yi.web.base.BaseController;

import com.jfinal.core.Const;

@Action(action = "/admin")
public class AdminIndexController  extends BaseController {

	public void index() {
		render("index.html");
	}
	
	public void login() {
		forwardAction("/admin/account/login");
	}

	public void logout() {
		this.forwardAction("/admin/account/logout");
	}
	
	/**
	 * generate verify code
	 */
	public void captcha(){
		String codeKey = UUID.randomUUID().toString();
		YiCaptchaRender captchRender = new YiCaptchaRender(codeKey);
		render(captchRender);
	}
	
	/**
	 * used for i18n
	 */
	public void setLocal()  {
		String local = getPara(Constants.COOKIE_LOCAL);
		// set default local: CHINA if empty
		local = StringUtils.isBlank(local) ? Locale.CHINA.toString() : local;
		setCookie("Constants.COOKIE_LOCAL", local, Const.DEFAULT_I18N_MAX_AGE_OF_COOKIE);
		renderNull();
	}
}
